package com.ss.android.article.base.feature.shrink.extend;

import android.content.Context;
import android.content.Intent;

import com.bytedance.common.utility.Logger;
import com.ss.android.common.shrink.extend.CoreExtendAdapter;
import com.ss.android.common.shrink.extend.CoreExtendSdkManager;

import java.util.HashMap;
import java.util.Map;

public class ArticleBaseExtendManager extends CoreExtendSdkManager {
    private Map mExtendLibAdapterMap = new HashMap();
    private static CoreExtendSdkManager sInstance = null;

    public ArticleBaseExtendManager() {
    }

    public static CoreExtendSdkManager getInstance() {
        if (ArticleBaseExtendManager.sInstance == null) {
            synchronized (ArticleBaseExtendManager.class) {
                if (ArticleBaseExtendManager.sInstance == null) {
                    ArticleBaseExtendManager.sInstance = new ArticleBaseExtendManager();
                }
            }
        }

        return ArticleBaseExtendManager.sInstance;
    }

    private CoreExtendAdapter loadThirdExtendLibAdapter(String className) {
        if (android.support.design.a.isTextEmpty(className)) {
            return null;
        }

        try {
            Object result = this.mExtendLibAdapterMap.get(className);
            if (result != null) {
                return (CoreExtendAdapter) result;
            }

            result = Class.forName(className).newInstance();
            CoreExtendAdapter adapter;
            if (!(result instanceof CoreExtendAdapter)) {
                adapter = null;
            } else {
                adapter = (CoreExtendAdapter) result;
            }
            try {
                this.mExtendLibAdapterMap.put(className, adapter);
                Logger.d("CoreExtendAdapter", "load ThirdExtendLibAdapter done: " + className);
                return (CoreExtendAdapter) result;
            } catch (Throwable throwable) {
            }
        } catch (Throwable throwable) {
            Logger.w("CoreExtendAdapter", "load " + className + " has exception: " + throwable);
            return null;
        }
        return null;
    }

    public final boolean loadUgrReadApkAdapter2(Context context) {
        return this.loadThirdExtendLibAdapter("com.ss.android.article.base.feature.shrink.extend.UgrReadApkAdapter") == null && super.loadUgrReadApkAdapter2(context);
    }

    public final Intent loadUgrReadApkAdapter(Context context) {
        return this.loadThirdExtendLibAdapter("com.ss.android.article.base.feature.shrink.extend.UgrReadApkAdapter") == null ? super.loadUgrReadApkAdapter(context) : null;
    }

    public final void loadGoogleAdAdapter() {
        this.loadThirdExtendLibAdapter("com.ss.android.article.base.feature.shrink.extend.GoogleAdAdapter");
    }

    public final void loadRegistDeviceManagerAdapter() {
        this.loadThirdExtendLibAdapter("com.ss.android.article.base.feature.shrink.extend.RegistDeviceManagerAda");
    }

    public final void loadBaiduStatisticsAdapter() {
        this.loadThirdExtendLibAdapter("com.ss.android.article.base.feature.shrink.extend.BaiduStatisticsAdapter");
    }

    public final void loadAppseeStatisticsAdapter() {
        this.loadThirdExtendLibAdapter("com.ss.android.article.base.feature.shrink.extend.AppseeStatisticsAdapter");
    }
}

